home *** CD-ROM | disk | FTP | other *** search
- #!/usr/bin/perl5
- #
- # inityp
- #
- # Copyright 1988-1996 Silicon Graphics, Inc.
- # All rights reserved.
- #
- # This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
- # the contents of this file may not be disclosed to third parties, copied or
- # duplicated in any form, in whole or in part, without the prior written
- # permission of Silicon Graphics, Inc.
- #
- # RESTRICTED RIGHTS LEGEND:
- # Use, duplication or disclosure by the Government is subject to restrictions
- # as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
- # and Computer Software clause at DFARS 252.227-7013, and/or in similar or
- # successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
- # rights reserved under the Copyright Laws of the United States.
- #
- # $Id: inityp,v 1.6 1997/04/17 23:38:19 shotes Exp $
-
- $yproot_dir = "/var/yp";
- $XFR = "/usr/sbin/ypxfr";
- $hf = "/tmp/ypinit.hostlist\.".$$;
- $YPM = $yproot_dir."/ypmake";
- $chkconfig = "/sbin/chkconfig";
-
- $masterp = "F";
- $slavep = "F";
- $host = "";
- $def_dom = "";
- $master = "";
- $got_host_list = "F";
- $exit_on_error = "F";
- $errors_in_setup = "F";
- $new_dm = "";
-
- sub
- usage
- {
- print "usage: inityp \[-m\] \[-d nis_domain \] [-l slave_server list\]\|\[-s master_server \]\n";
- die;
- }
-
- if ($> != 0) {
- print "You have to be the superuser to run this.\n";
- # die;
- }
-
- $i = 0;
- while ($i <= $#ARGV) {
- if ($ARGV[$i] eq "-m") {
- $masterp = "T";
- }
- elsif ($ARGV[$i] eq "-d") {
- $new_dm = $ARGV[$i+1];
- if ($new_dm eq "") {
- usage;
- }
- $i++;
- }
- elsif ($ARGV[$i] eq "-l") {
- @slave_list = split(/,/, $ARGV[$i+1]);
- $i++;
- }
- elsif ($ARGV[$i] eq "-s") {
- $slavep = "T";
- $master = $ARGV[$i+1];
- if ($master eq "") {
- usage;
- }
- $i++;
- }
- else {
- usage;
- }
- $i++;
- }
-
- chomp($host = `/usr/bsd/hostname`);
- chomp($def_dom = `/bin/domainname`);
-
- if ( (! -d $yproot_dir) || (-f $yproot_dir) ) {
- print "The directory $yproot_dir doesn't exist.\n";
- die;
- }
-
- if ($slavep eq "T") {
- if ($host eq $master) {
- print "The Master and Slave systems need to be distinct.\n";
- die;
- }
- @ents = `/bin/ypwhich -m | /bin/egrep $master`;
- undef @maps;
- for ($i = 0; $i <= $#ents; $i++) {
- ($maps[$i], $x) = split(/\s+/, $ents[$i]);
- }
- $dom = $def_dom;
- }
-
- if ($masterp eq "T") {
- if ($new_dom eq "") {
- $dom = $def_dom;
- }
- else {
- system("/bin/domainname", $new_dm);
- $dom = $new_dm;
- }
- }
-
- if (-d "$yproot_dir/$dom") {
- opendir(YPDIR, "$yproot_dir/$dom") || die "Unable to open directory $yproot_dir/$dom";
- @fnames = readdir(YPDIR);
- closedir(YPDIR);
- for ($i = 0; $i <= $#fnames; $i++) {
- if( ($fnames[$i] eq ".") || ($fnames[$i] eq "..") ) {
- next;
- }
- if (-d $fnames[$i]) {
- system ("/bin/rm", "-r", "-f", $fnames[$i]);
- mkdir ($fnames[$i], 0755);
- }
- }
- }
- else {
- mkdir ("$yproot_dir/$dom", 0755);
- }
-
- if ($slavep eq "T") {
- for ($i = 0; $i <= $#maps; $i++) {
- system ($XFR, "-h", $master, "-c", "-d", $dom, $maps[$i]);
- }
- system ($chkconfig, "-f", "ypserv", "on");
- system ($chkconfig, "-f", "yp", "on");
- }
- else {
- chdir($yproot_dir);
- unlink(<*.time>);
- # prevent warning first time ypmake runs
- open(LOGFL, ">$yproot_dir/ypmake.log.old");
- close(LOGFL);
-
- open(YPSRV, ">$yproot_dir/ypservers") || die "Failed to open $yproot_dir/ypservers.\n";
- print YPSRV "$host\n";
- print YPSRV join('\n', @slave_list);
- close(YPSRV);
-
- `$YPM NOPUSH=1`;
-
- system ($chkconfig, "-f", "ypmaster", "on");
- system ($chkconfig, "-f", "ypserv", "on");
- system ($chkconfig, "-f", "yp", "on");
- }
-